package com.west_traveler.ximalayafm;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.mock.MockApplication;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import com.west_traveler.application.BaseApplication;
import com.west_traveler.entity.entity_welcome_page.FirstDataLayer;
import com.west_traveler.entity.entity_welcome_page.WelcomeData;
import com.west_traveler.inteface.WelcomeHttpService;

import java.io.IOException;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WelcomePageActivity extends AppCompatActivity implements Callback<FirstDataLayer> {

    private ImageView ivWelcome;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==1) {
                startActivity(new Intent(WelcomePageActivity.this,MainActivity.class));
                finish();
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_page);

        //欢迎界面控件
        ivWelcome = ((ImageView) findViewById(R.id.iv_welcome_id));

        ((BaseApplication) getApplication())
                .getWelcomeHttpService()
                .getWelcomeFirstData()
                .enqueue(this);
    }

    @Override
    public void onResponse(Call<FirstDataLayer> call, Response<FirstDataLayer> response) {
        List<WelcomeData> data =  response.body().getData();
        try {
                Thread.sleep(3000);
            Picasso.with(this).load(data.get(0).getCover()).into(ivWelcome);
            Log.i("调试","第一个加载完");
            handler.sendEmptyMessageDelayed(1,3000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }




    }

    @Override
    public void onFailure(Call<FirstDataLayer> call, Throwable t) {

    }
}
